// 如何使用jql触发器请参考文档：https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html
module.exports = {
	trigger: {
		beforeCreate: async function({
			collection,
			operation,
			where,
			addDataList,
			clientInfo
		} = {}) {
			const now = Date.now()
			for (let i = 0; i < addDataList.length; i++) {
				const addDataItem = addDataList[i]
				addDataItem.updateTime = now // 更新数据的update_date字段赋值为当前服务器时间
				addDataItem.createTime = now
			}
		},
		beforeUpdate: async function({
			collection,
			operation,
			where,
			updateData,
			clientInfo
		} = {}) {
			const id = where && where._id
			console.log(id, updateData)
			if (typeof id === 'string') {
				updateData.updateTime = Date.now() // 更新数据的update_date字段赋值为当前服务器时间
			}
		}
	}
}